home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Programming / AMarquee / examples / amarqueedebug.c < prev    next >
C/C++ Source or Header  |  1998-06-24  |  7KB  |  183 lines

  1.  
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6. #include <dos/dos.h>
  7. #include <clib/dos_protos.h>
  8. #include <clib/exec_protos.h>
  9.  
  10. #include <clib/AMarquee_protos.h>
  11.  
  12. #include <pragmas/AMarquee_pragmas.h>
  13.  
  14. struct Library * AMarqueeBase = NULL;
  15. struct QSession * session     = NULL;
  16.  
  17. /* Takes user input until blank line is typed */
  18. void ProcessDebugCommands(struct QSession * session)
  19. {
  20.   while(1)
  21.   {
  22.    char debugline[500] = "\0\0\0\0\0\0\0\0";
  23.    char * keyword, * data;
  24.    ULONG dataLen = 0L;
  25.    LONG res;
  26.    
  27.    printf("Enter your debug command now: "); fflush(stdout);
  28.    gets(debugline);
  29.   
  30.    keyword = &debugline[2];
  31.    if (data = strchr(keyword,'='))
  32.    {
  33.      *data = '\0';  /* terminate the keyword */
  34.      data++;
  35.      dataLen = strlen(data)+1;
  36.    }
  37.    switch((int)(debugline[0]))
  38.    {
  39.      case '\0': res=QGo(session,0L);                           break;
  40.      case 'A':  res=QSetMessageAccessOp(session, keyword, -1); break;
  41.      case 'm':  res=QMessageOp(session, keyword, data, dataLen); break;
  42.      case 'M':  res=QSysMessageOp(session, keyword, data);   break;
  43.      case 'a':  res=QSetAccessOp(session, keyword);          break;
  44.      case 's':  res=QSetOp(session, keyword, data, dataLen); break;
  45.      case 'S':  res=QStreamOp(session, keyword, data, dataLen); break;
  46.      case 'r':  res=QRenameOp(session, keyword, data);       break;
  47.      case 'D':  res=QDebugOp(session, keyword);              break;
  48.      case 'g':  res=QGetOp(session, keyword, -1);            break;
  49.      case 'd':  res=QDeleteOp(session, keyword);             break;
  50.      case 'i':  res=QInfoOp(session);                        break;
  51.      case 'c':  res=QSubscribeOp(session, keyword, -1);      break;
  52.      case 'C':  res=QGetAndSubscribeOp(session, keyword, -1);     break;
  53.      case 'k':  res=QClearSubscriptionsOp(session,atoi(keyword)); break;
  54.      case 'p':  res=QPingOp(session);                             break;
  55.      case 'v':  res=QRequestPrivilegesOp(session,atol(keyword));  break;
  56.      case 'w':  res=QReleasePrivilegesOp(session,atol(keyword));  break;
  57.      case '!':  res=QKillClientsOp(session,keyword);              break;
  58.      case '?':  res=QGetParameterOp(session,keyword);             break;
  59.      case '$':  res=QSetParameterOp(session,keyword,data);        break;
  60.      default:   printf("Command code %c was not recognized.\n",debugline[0]); break;
  61.    }
  62.    printf("(Op result was %i)\n",res);
  63.    if (debugline[0] == '\0') return;
  64.   }
  65. }
  66.  
  67.  
  68. void CleanExit(void)
  69. {
  70. printf("\nCleaning up...\n");
  71.   if (session)      QFreeSession(session);        /* This MUST be done before we close the library! */
  72.   if (AMarqueeBase) CloseLibrary(AMarqueeBase);  
  73.   printf("All done.\n");
  74. }
  75.  
  76. /* Main program */
  77. int main(int argc, char ** argv)
  78. {
  79.   char * connectTo, * progName;
  80.   int port;
  81.     
  82.   printf("Usage Note:  AMarqueeDebug [hostname=localhost] [myname=debug] [port=2957]\n");  
  83.   atexit(CleanExit);
  84.   
  85.   connectTo = (argc>1) ? argv[1] : "localhost";
  86.   progName  = (argc>2) ? argv[2] : "debug";
  87.   port      = (argc>3) ? atoi(argv[3]) : 2957;
  88.  
  89.   if ((AMarqueeBase = OpenLibrary("amarquee.library",46L)) == NULL)
  90.   {
  91.     printf("Couldn't open amarquee.library v46!\n");
  92.     exit(RETURN_ERROR);
  93.   }
  94.   printf("Connecting to %s:%i\n",connectTo, port);
  95.  
  96. #ifdef ASYNC_CONNECT
  97.   if ((session = QNewSessionAsync(connectTo, port, progName)) == NULL)
  98.   {
  99.     printf("Couldn't connect to server %s:%i\n",connectTo, port);
  100.     exit(RETURN_WARN);
  101.   }
  102. #else
  103.   if ((session = QNewSession(connectTo, port, progName)) == NULL)
  104.   {
  105.     printf("Couldn't connect to server %s:%i\n",connectTo, port);
  106.     exit(RETURN_WARN);
  107.   }
  108. #endif
  109.  
  110.   printf("Connected to server %s:%i\n",connectTo, port);
  111.  
  112. #ifdef WANT_INSTANT_SAMPLE_DATA
  113.   /* Setup some sample data */
  114.   (void)QSetOp(session, "sampledata",             "Kids",    5);
  115.   (void)QSetOp(session, "sampledata/Jeremy",      "1",       2);
  116.   (void)QSetOp(session, "sampledata/Joanna",      "2",       2);
  117.   (void)QSetOp(session, "sampledata/Joanna/nerd", "yep! :)", 8);
  118.   (void)QSetOp(session, "sampledata/Joellen",     "3",       2);
  119.   (void)QSetOp(session, "sampledata/Charcoal",    "Kitty!",  7);
  120.   (void)QGo(session, 0L);
  121. #endif
  122.  
  123.   printf("Commands are:\n");
  124.   printf("\n");
  125.   printf("a wildhostpath   Access control (default is /#?/#?)\n");
  126.   printf("A wildhostpath   Access control for incoming messages (default in no access)\n");
  127.   printf("m hosts=data     Send an active message to hosts\n");
  128.   printf("M hosts=string   Send an system message to hosts\n");
  129.   printf("s path=data      Set data node value\n");
  130.   printf("S path=data      Stream data node value\n");
  131.   printf("r path=newlabel  Rename data node\n");
  132.   printf("D debugstring    Send debug string\n");
  133.   printf("g wildpath       Get a node or nodes\n");
  134.   printf("c wildpath       Subscribe to a node or nodes\n");
  135.   printf("C wildpath       Get&Subscribe to a node or nodes\n");
  136.   printf("k opID           Klear subscriptions (by id or 0 for all)\n");
  137.   printf("d wildpath       Delete a node or nodes\n");
  138.   printf("i                Request info packet\n");
  139.   printf("p                Request ping packet\n");
  140.   printf("v #              Request new privileges (by code bitchord)\n");
  141.   printf("w #              Release existing privileges (by code bitchord)\n");
  142.   printf("! hosts          Kill other clients (requires KILLCLIENTS privilege!)\n");
  143.   printf("$ param=string   Set a parameter with QSetParam()\n");
  144.   printf("? param          Get a parameter by name\n");
  145.   printf("<enter>          Send accumulated transactions (GO!!)\n");
  146.   printf("\n");
  147.   printf("Press CTRL-F to enter commands, or CTRL-C to quit\n");
  148.   
  149.   while(1)
  150.   {
  151.     struct QMessage * qMsg;
  152.     ULONG signals = (1L << session->qMsgPort->mp_SigBit) | (SIGBREAKF_CTRL_C) | (SIGBREAKF_CTRL_F);
  153.  
  154.     /* Wait for next message from the server */
  155.     signals = Wait(signals);
  156.     
  157.     if (signals & (1L << session->qMsgPort->mp_SigBit))
  158.     {
  159.       while(qMsg = (struct QMessage *) GetMsg(session->qMsgPort))
  160.       {
  161.         struct QRunInfo * inf = (qMsg->qm_DataLen == sizeof(struct QRunInfo)) ? ((struct QRunInfo *) qMsg->qm_Data) : NULL;
  162.  
  163.         /* Handle message */
  164.         printf("Message %p recieved---------\n",qMsg);
  165.         printf("Status:       %i (%s)\n",  qMsg->qm_Status, QErrorName(qMsg->qm_Status));
  166.         printf("Error Line:   %i\n",  qMsg->qm_ErrorLine);
  167.         printf("Message ID:   %i\n",  qMsg->qm_ID);
  168.         printf("Path:        [%s]\n", qMsg->qm_Path?qMsg->qm_Path:"<NULL>");
  169.         printf("Data:        [%s](int=%i)\n", qMsg->qm_Data?qMsg->qm_Data:((UBYTE*)"<NULL>"),qMsg->qm_Data?(*((int*)qMsg->qm_Data)):0);
  170.         printf("DataLen:      %lu\n", qMsg->qm_DataLen);
  171.         printf("ActualLen:    %lu\n", qMsg->qm_ActualLen);
  172.  
  173.         if (inf) printf("Info: alloced:%li allowed:%li avail:%li curPrivs=0x%x posPrivs=0x%x\n",
  174.           inf->qr_Alloced, inf->qr_Allowed, inf->qr_Avail, inf->qr_CurrentPrivs, inf->qr_PossiblePrivs); 
  175.         FreeQMessage(session, qMsg);
  176.       }
  177.     }
  178.     if (signals & SIGBREAKF_CTRL_F) ProcessDebugCommands(session);
  179.     if (signals & SIGBREAKF_CTRL_C) break;  /* Quit if CTRL-C pressed */
  180.   }
  181.   /* CleanExit() called here! */
  182. }
  183.